#!/usr/bin/env ruby
require 'set'

repo_set = Set[]
sys_set = Set[]

while (line = STDIN.gets)
  case line.chomp!
  # Error: Unable to find a match: docker-registry mock xx
  when /Error: Unable to find a match: (.+)/
    $1.split.each do |repo|
       repo_set << repo
    end

  # Error: Unknown repo: 'powertools'
  when /Error: Unknown repo: (.+)/
    repo = $1.delete!("'")
    puts "eid.unknown-repo.#{repo}: 001"
    puts "unknown-repo.#{repo}.message: #{line}"

  # Error: Module or Group 'convert' does not exist.
  when /Error: Module or Group ('[^\s]+')/
    repo = $1.delete!("'")
    puts "eid.error.not-exist-module-or-group.#{repo}: 001"
    puts "error.not-exist-module-or-group.#{repo}.message: #{line}"
  # /bin/sh: passwd: command not found
  when /\/bin\/sh: (.+): command not found/
    puts "eid.sh.command-not-found.#{$1}: 001"
    puts "sh.command-not-found.#{$1}.message: #{line}"

  # RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
  # yum swap: error: unrecognized arguments: install systemd systemd-libs
  when /yum swap: error: .*: install (.+)/
    $1.split.each do |sys|
      sys_set << sys
    end

  # curl: (22) The requested URL returned error: 404 Not Found
  # error: skipping https://dl.fedoraproject.org/pub/epel/bash-latest-7.noarch.rpm - transfer failed
  when /.*error: .* (https.*)/
    puts "eid.requested-URL-returned.error: 001"
    puts "requested-URL-returned.error.message: #{line}"
  end
end

repo_set.each do |repo|
  puts "eid.yum.error.Unable-to-find-a-match.#{repo}: 001"
  puts "yum.error.Unable-to-find-a-match.#{repo}.message: Error: Unable to find a match: #{repo}"
end

sys_set.each do |sys|
    puts "eid.yum.swap.error.unrecognized-arguments-install.#{sys}: 001"
    puts "yum.swap.error.unrecognized-arguments.#{sys}.message: yum swap: error: unrecognized arguments: install #{sys}"
end
